<?php
require_once( 'Database.class.php' );

class User extends Database {

	public function __construct() {
		parent::__construct();
		parent::connect();
	}

	public function getUser($conditions = null){
		$strCond = '';
		$query = '';
		if(is_array($conditions)){
			foreach ($conditions as $key =>$value) {
				$strCond .= $key.' = '.$value . ' ';
			}
			$query = 'SELECT yu.id, yu.user_id
				 FROM user  yu
				 WHERE '.$strCond ;
		}
		else{
			$query = 'SELECT yu.id, yu.user_id
				FROM user  yu';
		}
		return Database::executeSQL($query,2);
	}

	/**
	 * 
	 * Inser in user Table	 
	 * @param facebook userId: $userId
	 */
	public function insertUser( $userId = null ){
		$query = 'INSERT  INTO user(id, date_created, date_updated)
					VALUES("'.mysql_real_escape_string($userId).'", SYSDATE(), SYSDATE())';
		return $this->executeQuery($query);
		
	}
	
	public function checkUser($userId){
		$query = 'SELECT *
		FROM user
		WHERE id = '.$userId;				
		return count(Database::executeSQL($query));
	}
	
}